<template>
  <amis-renderer :schema="schema" :locals="locals" />
</template>
<script>
import AMISRenderer from '@/components/amis-render/index.vue'

const schema = {
  "type": "page",
  "title": "Hello world",
  "body": [
    {
      "type": "crud2",
      "id": "u:9deadc1fd2f6",
      "mode": "table2",
      "dsType": "api",
      "syncLocation": true,
      "selectable": true,
      "multiple": true,
      "primaryField": "id",
      "loadType": "pagination",
      "api": {
        "url": "/api/lowcode/pages",
        "method": "get"
      },
      "filter": {
        "type": "form",
        "title": "条件查询",
        "mode": "inline",
        "columnCount": 3,
        "clearValueOnHidden": true,
        "behavior": [
          "SimpleQuery"
        ],
        "body": [
          {
            "name": "id",
            "label": "ID",
            "type": "input-text",
            "size": "full",
            "required": false,
            "behavior": "SimpleQuery",
            "id": "u:20b77fb12fe0"
          },
          {
            "name": "page_name",
            "label": "页面名称",
            "type": "input-text",
            "size": "full",
            "required": false,
            "behavior": "SimpleQuery",
            "id": "u:88a1c96400ef"
          },
          {
            "name": "created_at",
            "label": "创建时间",
            "type": "input-text",
            "size": "full",
            "required": false,
            "behavior": "SimpleQuery",
            "id": "u:2727c9856dcc"
          },
          {
            "name": "updated_at",
            "label": "更新时间",
            "type": "input-text",
            "size": "full",
            "required": false,
            "behavior": "SimpleQuery",
            "id": "u:bc56bb6c6a9e"
          }
        ],
        "actions": [
          {
            "type": "reset",
            "label": "重置",
            "id": "u:40e8b545b49a"
          },
          {
            "type": "submit",
            "label": "查询",
            "level": "primary",
            "id": "u:e60cf73237ed"
          }
        ],
        "id": "u:eaaaf8a7ad95",
        "feat": "Insert"
      },
      "headerToolbar": [
        {
          "type": "flex",
          "direction": "row",
          "justify": "flex-start",
          "alignItems": "stretch",
          "style": {
            "position": "static"
          },
          "items": [
            {
              "type": "container",
              "align": "left",
              "behavior": [
                "Insert",
                "BulkEdit",
                "BulkDelete"
              ],
              "body": [
                {
                  "type": "button",
                  "label": "新增",
                  "level": "primary",
                  "className": "m-r-xs",
                  "behavior": "Insert",
                  "onEvent": {
                    "click": {
                      "actions": [
                        {
                          "actionType": "dialog",
                          "dialog": {
                            "type": "dialog",
                            "body": [
                              {
                                "id": "u:d3de145b614e",
                                "type": "form",
                                "title": "新增数据",
                                "mode": "flex",
                                "labelAlign": "top",
                                "dsType": "api",
                                "feat": "Insert",
                                "body": [
                                  {
                                    "name": "page_name",
                                    "label": "页面名称",
                                    "row": 0,
                                    "type": "input-text",
                                    "id": "u:5cac504d15a1"
                                  },
                                  {
                                    "name": "config_json",
                                    "label": "config_json",
                                    "row": 2,
                                    "type": "input-text",
                                    "id": "u:492cc740f2a1",
                                    "colSize": "1",
                                    "visible": false,
                                    "value": "{\n  \"type\": \"page\",\n  \"body\": \"这是新增的页面!\"\n}"
                                  }
                                ],
                                "resetAfterSubmit": true,
                                "actions": [
                                  {
                                    "type": "button",
                                    "actionType": "cancel",
                                    "label": "取消"
                                  },
                                  {
                                    "type": "button",
                                    "actionType": "submit",
                                    "label": "提交",
                                    "level": "primary"
                                  }
                                ],
                                "onEvent": {
                                  "submitSucc": {
                                    "actions": [
                                      {
                                        "actionType": "search",
                                        "groupType": "component",
                                        "componentId": "u:9deadc1fd2f6"
                                      }
                                    ]
                                  }
                                }
                              }
                            ],
                            "title": "新增数据",
                            "size": "md",
                            "actions": [
                              {
                                "type": "button",
                                "actionType": "cancel",
                                "label": "取消",
                                "id": "u:af960dae7282"
                              },
                              {
                                "type": "button",
                                "actionType": "submit",
                                "label": "提交",
                                "level": "primary",
                                "id": "u:816c7365b5ba",
                                "disabledOnAction": false,
                                "onEvent": {
                                  "click": {
                                    "weight": 0,
                                    "actions": [
                                      {
                                        "ignoreError": false,
                                        "outputVar": "responseResult",
                                        "actionType": "ajax",
                                        "options": {},
                                        "api": {
                                          "url": "/api/lowcode/add_pages",
                                          "method": "post",
                                          "requestAdaptor": "",
                                          "adaptor": "",
                                          "messages": {},
                                          "dataType": "json",
                                          "data": {
                                            "&": "$$"
                                          }
                                        }
                                      }
                                    ]
                                  }
                                }
                              }
                            ],
                            "actionType": "dialog",
                            "id": "u:416e4731623a"
                          }
                        }
                      ]
                    }
                  },
                  "id": "u:785a5c106c54",
                  "disabledOnAction": false,
                  "themeCss": {
                    "className": {
                      "padding-and-margin:default": {
                        "marginTop": "var(--sizes-size-5)",
                        "marginRight": "var(--sizes-size-5)",
                        "marginBottom": "var(--sizes-size-5)",
                        "marginLeft": "var(--sizes-size-5)"
                      }
                    }
                  }
                },
                {
                  "type": "button",
                  "label": "批量删除",
                  "behavior": "BulkDelete",
                  "level": "danger",
                  "className": "m-r-xs",
                  "confirmText": "确认要批量删除数据「${JOIN(ARRAYMAP(selectedItems, item => item.id), ',')}」",
                  "disabledOn": "${selectedItems != null && selectedItems.length < 1}",
                  "onEvent": {
                    "click": {
                      "actions": [
                        {
                          "actionType": "ajax",
                          "api": ""
                        },
                        {
                          "actionType": "search",
                          "groupType": "component",
                          "componentId": "u:9deadc1fd2f6"
                        }
                      ]
                    }
                  },
                  "id": "u:8f9ef1544d00",
                  "disabledOnAction": false,
                  "themeCss": {
                    "className": {
                      "padding-and-margin:default": {
                        "marginTop": "var(--sizes-size-5)",
                        "marginRight": "var(--sizes-size-5)",
                        "marginBottom": "var(--sizes-size-5)",
                        "marginLeft": "var(--sizes-size-5)"
                      }
                    }
                  }
                }
              ],
              "wrapperBody": false,
              "style": {
                "flexGrow": 1,
                "flex": "1 1 auto",
                "position": "static",
                "display": "flex",
                "flexBasis": "auto",
                "flexDirection": "row",
                "flexWrap": "nowrap",
                "alignItems": "stretch",
                "justifyContent": "flex-start"
              },
              "id": "u:21e1fe6218df"
            },
            {
              "type": "container",
              "align": "right",
              "behavior": [
                "FuzzyQuery"
              ],
              "body": [],
              "wrapperBody": false,
              "style": {
                "flexGrow": 1,
                "flex": "1 1 auto",
                "position": "static",
                "display": "flex",
                "flexBasis": "auto",
                "flexDirection": "row",
                "flexWrap": "nowrap",
                "alignItems": "stretch",
                "justifyContent": "flex-end"
              },
              "id": "u:1de82614afab"
            }
          ],
          "id": "u:e7d3d6f169b3"
        }
      ],
      "footerToolbar": [
        {
          "type": "flex",
          "direction": "row",
          "justify": "flex-start",
          "alignItems": "stretch",
          "style": {
            "position": "static"
          },
          "items": [
            {
              "type": "container",
              "align": "left",
              "body": [],
              "wrapperBody": false,
              "style": {
                "flexGrow": 1,
                "flex": "1 1 auto",
                "position": "static",
                "display": "flex",
                "flexBasis": "auto",
                "flexDirection": "row",
                "flexWrap": "nowrap",
                "alignItems": "stretch",
                "justifyContent": "flex-start"
              },
              "id": "u:1ab7f64037eb"
            },
            {
              "type": "container",
              "align": "right",
              "body": [
                {
                  "type": "pagination",
                  "behavior": "Pagination",
                  "layout": [
                    "total",
                    "perPage",
                    "pager"
                  ],
                  "perPage": 10,
                  "perPageAvailable": [
                    10,
                    20,
                    50,
                    100
                  ],
                  "align": "right",
                  "id": "u:c7ec9382a314"
                }
              ],
              "wrapperBody": false,
              "style": {
                "flexGrow": 1,
                "flex": "1 1 auto",
                "position": "static",
                "display": "flex",
                "flexBasis": "auto",
                "flexDirection": "row",
                "flexWrap": "nowrap",
                "alignItems": "stretch",
                "justifyContent": "flex-end"
              },
              "id": "u:ea548b78c74c"
            }
          ],
          "id": "u:cc3475038291"
        }
      ],
      "columns": [
        {
          "type": "tpl",
          "title": "ID",
          "name": "id",
          "id": "u:2c841c00addf"
        },
        {
          "type": "tpl",
          "title": "页面名称",
          "name": "page_name",
          "id": "u:2bef29fbc496"
        },
        {
          "type": "tpl",
          "title": "创建时间",
          "name": "created_at",
          "id": "u:73060f9fcb2d"
        },
        {
          "type": "tpl",
          "title": "更新时间",
          "name": "updated_at",
          "id": "u:af9c6b586073"
        },
        {
          "type": "operation",
          "title": "操作",
          "buttons": [
            {
              "label": "可视化编辑页面",
              "level": "link",
              "id": "u:e585cc8027d6",
              "disabledOnAction": false,
              "onEvent": {
                "click": {
                  "weight": 0,
                  "actions": [
                    {
                      "ignoreError": false,
                      "actionType": "url",
                      "args": {
                        "url": "/edit/0?page_name=${page_name}&page_id=${id}"
                      }
                    }
                  ]
                }
              }
            },
            {
              "type": "button",
              "label": "编辑",
              "level": "link",
              "behavior": "Edit",
              "onEvent": {
                "click": {
                  "actions": [
                    {
                      "actionType": "dialog",
                      "dialog": {
                        "body": {
                          "id": "u:d6993e37c5a0",
                          "type": "form",
                          "title": "编辑数据",
                          "mode": "flex",
                          "labelAlign": "top",
                          "dsType": "api",
                          "feat": "Edit",
                          "body": [],
                          "resetAfterSubmit": true,
                          "actions": [
                            {
                              "type": "button",
                              "actionType": "cancel",
                              "label": "取消"
                            },
                            {
                              "type": "button",
                              "actionType": "submit",
                              "label": "提交",
                              "level": "primary"
                            }
                          ],
                          "onEvent": {
                            "submitSucc": {
                              "actions": [
                                {
                                  "actionType": "search",
                                  "groupType": "component",
                                  "componentId": "u:9deadc1fd2f6"
                                }
                              ]
                            }
                          }
                        },
                        "title": "编辑数据",
                        "size": "md",
                        "actions": [
                          {
                            "type": "button",
                            "actionType": "cancel",
                            "label": "取消"
                          },
                          {
                            "type": "button",
                            "actionType": "submit",
                            "label": "提交",
                            "level": "primary"
                          }
                        ],
                        "type": "dialog",
                        "actionType": "dialog"
                      }
                    }
                  ]
                }
              },
              "id": "u:3a2b89982205"
            },
            {
              "type": "button",
              "label": "删除",
              "behavior": "Delete",
              "className": "m-r-xs text-danger",
              "level": "link",
              "confirmText": "确认要删除数据",
              "onEvent": {
                "click": {
                  "actions": [
                    {
                      "actionType": "ajax",
                      "data": {
                        "&": "$$"
                      }
                    },
                    {
                      "actionType": "search",
                      "groupType": "component",
                      "componentId": "u:9deadc1fd2f6"
                    }
                  ]
                }
              },
              "id": "u:084cb701eab5"
            },
            {
              "label": "查看",
              "level": "link",
              "id": "u:31dacb98057c",
              "type": "button",
              "behavior": "View",
              "onEvent": {
                "click": {
                  "actions": [
                    {
                      "actionType": "dialog",
                      "dialog": {
                        "body": {
                          "id": "u:61e18a944aed",
                          "type": "form",
                          "title": "查看数据",
                          "mode": "flex",
                          "labelAlign": "top",
                          "dsType": "api",
                          "feat": "View",
                          "body": [],
                          "static": true,
                          "actions": [
                            {
                              "type": "button",
                              "actionType": "cancel",
                              "label": "关闭"
                            }
                          ],
                          "onEvent": {
                            "submitSucc": {
                              "actions": [
                                {
                                  "actionType": "search",
                                  "groupType": "component",
                                  "componentId": "u:9deadc1fd2f6"
                                }
                              ]
                            }
                          }
                        },
                        "title": "查看数据",
                        "size": "md",
                        "actions": [
                          {
                            "type": "button",
                            "actionType": "cancel",
                            "label": "关闭"
                          }
                        ],
                        "type": "dialog",
                        "actionType": "dialog"
                      }
                    }
                  ]
                }
              }
            }
          ],
          "id": "u:82fadd8da563"
        }
      ]
    }
  ],
  "id": "u:4b5ca70a012c",
  "asideResizor": false,
  "pullRefresh": {
    "disabled": true
  },
  "toolbar": [],
  "regions": [
    "body"
  ],
  "definitions": {}
}
export default {
  name: 'Table',
  components: {
    'amis-renderer': AMISRenderer
  },
  computed: {},
  data: () => ({
    schema: schema,
    locals: {}
  })
}
</script>
